/***************************************************************************************
Firm-embedded productivity and cross-country income differences
Alviarez, Cravino and Ramondo
Journal of Political Economy (2022)

Program: table_02_correlation.do
Date: October 2022

Description: Reproduces Table 2: Correlations with country characteristics.

*****************************************************************************************/

*-------------------------------------------------------------------------------
global typeden=1
include "set_directories.do"
set memory 64g
global lf "LF"

*Log
cap log close
log using "${clogs}/table_02_correlation.log",replace
*-------------------------------------------------------------------------------




************************ TABLE 2  **************************
clear all
use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

local grvar0 "gdp_pw_ppp" 
local grvar1 ""	
local rr ""
local var3 "A"
local yy "2016"
local yy_ref=`yy'	
replace year=`yy_ref'
merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
drop if _merge==2
drop _merge

foreach var in D_A  {
gen `var'_phi=(-1)*`var'*(0.2)
*---------------------------------------
gen b_`var'_phi_`grvar0'=ln_`grvar0' - `var'_phi
}

local LHS1 D_`var3'_phi
local LHS2 b_D_`var3'_phi_`grvar0'
local RHS ln_`grvar0'


*Bring some aggregate control variables
*----------------------------------------------------------
merge m:1 year isocode using "${data}/additional_agg_indicators.dta"
drop if _merge==2
drop _merge

gen k_y=ln_ck-ln_rgdpo
gen ln_patent=ln(patent_total)
gen ln_patent_pc=ln_patent-ln_pop
gen ln_trademark=ln(trademark_application)
gen ln_trademark_pc=ln_trademark-ln_pop
gen ln_researcher_permm=ln(Researchers_RD_permm)
gen ln_mobile_per100=ln(mobile_per100) 
gen ln_broadband_per100=ln(broadband_per100) 
gen ln_electric_pc=ln(electric_percapita) 
gen ln_freshwater_pc=ln(freshwater_percapita) 
gen ln_air_transp=ln(air_transp) 
gen ln_container_port=ln(container_port)
gen ln_schooling=ln(schooling)
egen gov_index=rowmean(PoliticalStability GovernmentEffectiveness RegulatoryQuality RuleofLaw ControlofCorruption)
egen gov_rank_index=rowmean(PoliticalStability_rank GovernmentEffectiveness_rank RegulatoryQuality_rank RuleofLaw_rank ControlofCorruption_rank)

tempfile temp
save `temp', replace 	


*Create table 2
*----------------------------------------
local var_dep "D_A_phi"
local typefirm "ln_patent_pc"
local abslist "year"
local clusterlist "isocode"
local variablelist "k_y ln_hc RuleofLaw"
local yy=2016
local grvar0 "gdp_pw_ppp" 

foreach vardep in "ln_`grvar0'" "D_A_phi" "b_D_A_phi"  {
display "`vardep'"

reghdfe `vardep' k_y ln_hc  if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
outreg2 using "${rmain}/table_02.xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 

reghdfe `vardep' k_y ln_hc  gov_rank_index ln_mobile_per100 ln_patent_pc if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
outreg2 using "${rmain}/table_02.xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 

}
*

log close 





